package mo.leetcode_top;

import java.util.HashMap;
import java.util.Map;

public class L454 {

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int n = nums1.length;
        Map<Integer, Integer> sum2count = new HashMap<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int sum = nums1[i] + nums2[j];
                sum2count.put(sum, sum2count.getOrDefault(sum, 0) + 1);
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                res += sum2count.getOrDefault(-(nums3[i]+nums4[j]), 0);
            }
        }
        return res;
    }



}
